import redis
from connect_to_redis import BaseRedisConnection


class TestzSet(BaseRedisConnection):
    # zadd/zrem:添加(修改)/删除成员
    # zcard/zcount:统计成员的数量
    # zscore：某个成员的分数（score）
    # zrange/zrevrange:按升序/降序查看成员
    # zrank/zrevrank:按升序/降序查看成员排名

    def test_zadd(self):
        # zadd/zrem:添加(修改)/删除成员
        rank = {
            '李明':3.25,
            '王浩':3.21,
            '张皓文':4.02,
            '吴文杰':4,
            '赵宇':3.53,
            '林峰':2.5
        }
        result = self.conn.zadd('swimming',rank)
        print(result)
        count = self.conn.zcount('swimming',0,100)
        print('count:',count)


    def test_zrem(self):
        # zadd/zrem:添加(修改)/删除成员
        result = self.conn.zrem('swimming','林峰')
        print(result)
        members = self.conn.zcount('swimming',0,100)
        print('count:',members)


    def course_analysis(self):
        # 比赛结果分析
        result = self.conn.zrange('swimming',0,-1)
        print(result)
        # 前3名
        result = self.conn.zrange('swimming', 0, 2)
        print(result)




def main():
    str_obj = TestzSet()
    # str_obj.test_zadd()
    # str_obj.test_zrem()
    str_obj.course_analysis()




if __name__ == '__main__':
    main()